package com.aphrodite.ui.widgets;

import javax.microedition.lcdui.Graphics;

/**
 * A simple line
 * 
 * @author kentelt
 * 
 */
public final class Line extends Widget {
	private short layout = LAYOUT_HORIZONTAL;
	int lineLen;

	int lineThick;

	/**
	 * 
	 * @param theme
	 * @param lineLength
	 *            in pixels
	 * @param lineThickness
	 *            in pixels
	 */
	public Line(Theme theme, int lineLength, int lineThickness) {
		super(theme, 1, 1);
		this.lineLen = lineLength;
		this.lineThick = lineThickness;
		updateModel();
	}

	public void render(Graphics g) {
		if (!isVisible)
			return;
		g.setColor(theme.fgColor);
		if (layout == LAYOUT_HORIZONTAL) {
			g.fillRoundRect(x, y, lineLen, lineThick, 3, 3);
		} else {
			g.fillRoundRect(x, y, lineThick, lineLen, 3, 3);
		}
	}

	public void setLayout(short layout) {
		this.layout = layout;
		updateModel();
		reDraw();
	}

	public void setLineLength(int length) {
		this.lineLen = length;
		updateModel();
		reDrawWidget();
	}

	public void setLineThickness(int thickness) {
		this.lineThick = thickness;
		updateModel();
		reDrawWidget();
	}

	/**
	 * Implementation override
	 */
	public void setTitle() {

	}

	protected void updateModel() {
		if (layout == LAYOUT_HORIZONTAL) {
			width = lineLen;
			height = lineThick;
		} else {
			height = lineLen;
			width = lineThick;
		}
	}
}
